package in.muton.edushare.pages.publicpages.userpages;

import in.muton.edushare.EduSharePage;
import in.muton.edushare.pages.FooterLinks;
import in.muton.edushare.url.URLLoader;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.edushare.common.constants.URLConstants;
import com.edushare.common.dao.UsersDAO;
import com.edushare.common.util.StringUtil;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.Users;

public abstract class UserPublicBase extends EduSharePage {
	
	protected IModel<Users> userModel;
	protected PageParameters params;
	
	public UserPublicBase(PageParameters params){
		this.params = params;
		String str = params.getString("0", "");
		String role = "member";
		Universities univ = null;
		add(new HeaderPanel("menuHeader"));
		if(!StringUtil.isValid(str) || new UsersDAO(getSessionORMInterface()).getUserFromUserName(str)==null){
			throw new RestartResponseException(URLLoader.getPageClass(URLConstants.PAGE_NOT_FOUND_PATH));
		}
		
		add(CSSPackageResource.getHeaderContribution(UserPublicBase.class, "UserPublicBase.css"));
		this.userModel=
				new CayenneModel<Users>(
						new UsersDAO(getSessionORMInterface()).getUserFromUserName(str));
		univ = (userModel.getObject().getRoleList()!=null && userModel.getObject().getRoleList().size()>0)?userModel.getObject().getRoleList().get(0).getUniversity():null;
		add(new Label("name", new PropertyModel<String>(this.userModel,"completeUserName")));
		
		String univName = univ!=null ? " | " + univ.getName():"";
		add(new Label("pagettl", userModel.getObject().getCompleteUserName() + univName));
		add(new UserRolePanel("userRole", userModel));
		add(new LeftMenuPanel("leftMenuDiv", userModel));
		add(new FooterLinks("footerLinks"));
	}
		
}
